﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace XYZCompiler
{
    static class CompilerHelper
    {
        public static TextBox OutPutBox = null;
        public static TextBox SourceTextBox = null;
        public static void Debug(string s)
        {
            OutPutBox.AppendText(s + "\r\n");
        }
        public static void SelectWord(int r,int c)
        {
            var start = SourceTextBox.GetFirstCharIndexFromLine(r-1);
            var end = SourceTextBox.GetFirstCharIndexFromLine(r );
            SourceTextBox.SelectionStart = start;
            SourceTextBox.SelectionLength =end -start-1;
            SourceTextBox.Focus();
        }
        public static void ShowResultDialog(FlowController.CompileState s,object result)
        {
            Form dialog;
            switch (s)
            {
                case FlowController.CompileState.ERROR:
                    break;
                case FlowController.CompileState.READY:
                    break;
                case FlowController.CompileState.LEXER_COMPLETED:
                    dialog = new ResultDialog.LexerResult(result);
                    dialog.ShowDialog();
                    break;
                case FlowController.CompileState.SYNTACTIC_COMPLETED:
                    dialog = new SyntacticResult(result);
                    dialog.ShowDialog();
                    break;
                case FlowController.CompileState.SEMANTIC_COMPELETED:
                    dialog = new ResultDialog.SemanticResult(result);
                    dialog.ShowDialog();
                    break;
                default:
                    throw new ArgumentOutOfRangeException("s");
            }
        }
    }
}
